//
//  Config.m
//  Bus
//
//  Created by wangjiajia on 13-7-10.
//  Copyright (c) 2013年 wangjiajia. All rights reserved.
//

#import "Config.h"
#import "AESCrypt.h"
@implementation Config

@synthesize isNetworkRunning;

+(void)saveUserName:(NSString *)username andPass:(NSString *)pwd{
    NSUserDefaults* settings=[NSUserDefaults standardUserDefaults];
    //无需删除，下次设置时直接覆盖？
    [settings removeObjectForKey:@"UserName"];
    [settings removeObjectForKey:@"Password"];
    
    [settings setObject:username forKey:@"UserName"];
    
    pwd=[AESCrypt encrypt:pwd password:[NSString stringWithFormat:@"%@@wjj",aes_pass]];
    [settings setObject:pwd forKey:@"Password"];
    
    [settings synchronize];
    
}

+(NSString *)getUserName{
    NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];
    return [settings objectForKey:@"UserName"];

}

+(NSString *)getPwd{
    NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];
    NSString * encryptpwd = [settings objectForKey:@"Password"];
    return [AESCrypt decrypt:encryptpwd password:[NSString stringWithFormat:@"%@@wjj",aes_pass]];
}


+(void)saveSiwtch_State:(BOOL)rememberPass andLogin:(BOOL)autoLogin{
    NSUserDefaults *settings=[NSUserDefaults standardUserDefaults];
    [settings setBool:rememberPass forKey:@"rememberPass"];
    [settings setBool:autoLogin forKey:@"autoLogin"];
    [settings synchronize];
}
+(BOOL)getSiwtch_AutoLogin_State{
    NSUserDefaults *settings=[NSUserDefaults standardUserDefaults];
    return  [settings boolForKey:@"autoLogin"];
}

+(BOOL)getSwitch_RememberPass_State{
    NSUserDefaults *settings=[NSUserDefaults standardUserDefaults];
    return  [settings boolForKey:@"rememberPass"];
}
//单例的声明 
static Config* _instance=nil;
+(Config *)instance{
    @synchronized(self){
        if (nil==_instance) {
            [self new];
        }
    }
    return _instance;
    
}

+(id)allocWithZone:(NSZone *)zone{
    @synchronized(self){
        if(nil==_instance){
            _instance=[super allocWithZone:zone];//super换成self 无限死循环啊
            return _instance;
        }
    }
    return nil;//其他人不可以alloc和new
}

@end
